package com.peng.leetcode.search;

/**
 * FindMin
 *
 * @author: lupeng6
 * @create: 2021/4/19 15:49
 */
public class FindMin {

    public static void main(String[] args) {
        int[] nums = {2, 2, 2, 0, 1};
        System.out.println(new FindMin().findMin(nums));
    }


    public int findMin(int[] nums) {
        int l = 0;
        int r = nums.length - 1;
        int startVal = nums[0];
        int endVal = nums[nums.length - 1];
        while (l < r) {
            int mid = (l + r) / 2;
            if (nums[mid] < endVal) {
                r = mid;
            } else if (nums[mid] > endVal) {
                l = mid + 1;
            } else {
                r--;
            }
        }
        return nums[l];
    }
}
